package pers.cz.logtail.handle;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import pers.cz.logtail.handle.adapter.LogSave;
import pers.cz.netty.handle.ServerMessageHandler;
import pers.cz.netty.protocal.Message;

/**
 * @program: PostGirl-panent
 * @description: 日志处理类
 * @author: Cheng Zhi
 * @create: 2022-10-05 11:41
 **/
@ChannelHandler.Sharable
public class LogHandle extends ServerMessageHandler {

    private LogSave logSave;
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, Message message) throws Exception {
       try {
/*           String content = (String) message.getContent();
           String ip = message.getAttachment("ip");
           String fileName = message.getAttachment("fileName");
           System.out.println("ip地址：" + ip);
           System.out.println("文件名称：" + fileName);*/
           ThreadPoolCfg.getThreadPool().execute(new Runnable() {
               @Override
               public void run() {
                   logSave.save(message);
               }
           });
           // 多线程处理
       } catch (Exception e) {
           e.printStackTrace();
       }
    }

    public void setLogSavePlan(LogSave logSave) {
        this.logSave = logSave;
    }
}
